package org.bronycorps.mlptss.domain.model;

import java.util.ArrayList;
import java.util.List;

import org.bronycorps.mlptss.domain.model.event.StateChangeEvent;
import org.bronycorps.mlptss.domain.model.event.StateChangeEventListener;

public class Bonus extends AbstractActorModel {

	public enum BonusType {
		BOMB, EXPLODE
	}

	private final BonusType bonusType;

	private float changeCoolDown;
	private boolean isMoney = false;
	private float maxChangeCoolDown = 3;
	private List<StateChangeEventListener> stateChangeListeners = new ArrayList<StateChangeEventListener>();

	public Bonus(BonusType type) {
		super();
		this.bonusType = type;

	}

	public boolean addListener(StateChangeEventListener e) {
		return this.stateChangeListeners.add(e);
	}

	public synchronized void fireStateChangeEvent() {
		for (StateChangeEventListener listener : this.stateChangeListeners) {
			listener.onStateChange(new StateChangeEvent(this));
		}
	}

	public BonusType getBonusType() {
		return this.bonusType;
	}

	@Override
	public int getLife() {
		return 0;
	}

	public boolean isMoney() {
		return this.isMoney;
	}

	public void reduceCooldowns(float delta) {
		this.changeCoolDown -= delta;

		if (this.changeCoolDown < 0) {
			// switch to other power
			this.isMoney = !this.isMoney;
			this.changeCoolDown = this.maxChangeCoolDown;
			fireStateChangeEvent();
		}
	}

	public boolean removeListener(StateChangeEventListener o) {
		return this.stateChangeListeners.remove(o);
	}
}
